package com.binfenhulian.chinaenergy.ces.manage.service.account;

import com.binfenhulian.chinaenergy.ces.core.exception.BaseException;
import com.binfenhulian.chinaenergy.ces.manage.bean.param.SessionParam;
import com.binfenhulian.chinaenergy.ces.manage.constants.Constants;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by wanghjbuf on 2018/3/20.
 */
@Service("com.binfenhulian.chinaenergy.ces.manage.service.account.OnlineServiceImpl")
public class OnlineServiceImpl implements OnlineService{

    @Override
    public SessionParam getOnlineUserByRequest(HttpServletRequest request) throws BaseException {
        try {
            HttpSession session = request.getSession();
            SessionParam sessionParam = (SessionParam) session.getAttribute(Constants.MANAGE_SESSION_KEY);
            if (null == sessionParam) {
                throw new BaseException("未发现对应的用户信息,操作失败");
            } else {
                return sessionParam;
            }
        } catch (Exception e) {
            throw new BaseException("系统未知错误,操作失败", e);
        }
    }
}
